
GameLoadingCtrl = {};
local this = GameLoadingCtrl;

local name;
--构建函数--
function GameLoadingCtrl.New()
	logWarn("GameLoadingCtrl.New--->>");
	this.ImgObjs = {};
	name = "GameLoading";
	return this;
end

function GameLoadingCtrl.Awake()
	logWarn("GameLoadingCtrl.Awake--->>");
	panelMgr:CreatePanel(name, this.OnCreate);
end

--启动事件--
function GameLoadingCtrl.OnCreate(obj)
	Game.UpdateCurrentPanel(name);
	
	this.InitLoadingMsg();
	logWarn("Start lua--->>"..obj.name);
end


function GameLoadingCtrl.SetPlayerProgress(userid,progress)
	if this.ImgObjs[userid] == nil then
	return;
	end
	local tweener =this.ImgObjs[userid]:DOFillAmount(progress,0.15);--.fillAmount = progress;
	
	if progress == 0 and userid == NetData:GetUserId() then
		tweener.onComplete = this.OnComplete;
		 
	end
end

function GameLoadingCtrl.OnComplete( )
	if NetData:GetUserState() == AckUserState.Login then
		--coroutine.start(this.WaitAndPush);
	else
		this.Push();
	end
end

function GameLoadingCtrl.ReLoginPush()
	this.Push();
end

function GameLoadingCtrl.SetAllLoadOver()
	--coroutine.step();
	--coroutine.stop(this.WaitAndPush);
	this.Push();
end

--初始匹配列表--
function GameLoadingCtrl.InitLoadingMsg()
	local playerList = NetData:GetPlayerList();
	local Text ;
	for i = 0,playerList.Length -1 do
		GameLoadingPanel.ImgTable[i+1].name = tostring(playerList[i].userid);
		Text = GameLoadingPanel.ImgTable[i+1].transform:Find("Text"):GetComponent('Text');
		GameLoadingPanel.ImgTable[i+1].color = ColorSwitch[playerList[i].heroid];
		Text.text = playerList[i].username;
		logError(playerList[i].username.."---"..playerList[i].heroid);
		this.ImgObjs[playerList[i].userid] = GameLoadingPanel.ImgTable[i+1].transform:Find("Image"):GetComponent('Image');

		if playerList[i].userid == NetData:GetUserId() then
			Text.color = ColorSwitch.nameColor;
		end
	end
	ViewMgr:LoadGameScene();
end


function GameLoadingCtrl.WaitAndPush()
	coroutine.wait(3);
	this.Push();
end

function GameLoadingCtrl.Push()
	Game.CreatePanel(CtrlNames.GamePlay);
end